home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / system-config-printer / probe_printer.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-29  |  3KB  |  141 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import socket
  5. import time
  6.  
  7. class LpdServer:
  8.     
  9.     def __init__(self, hostname):
  10.         self.hostname = hostname
  11.         self.max_lpt_com = 8
  12.  
  13.     
  14.     def _open_socket(self):
  15.         port = 515
  16.         
  17.         try:
  18.             (host, port) = self.hostname.split(':', 1)
  19.         except ValueError:
  20.             host = self.hostname
  21.  
  22.         s = None
  23.         
  24.         try:
  25.             ai = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
  26.         except socket.gaierror:
  27.             ai = []
  28.  
  29.         for res in ai:
  30.             (af, socktype, proto, canonname, sa) = res
  31.             
  32.             try:
  33.                 s = socket.socket(af, socktype, proto)
  34.             except socket.error:
  35.                 msg = None
  36.                 s = None
  37.                 continue
  38.  
  39.             
  40.             try:
  41.                 s.connect(sa)
  42.             except socket.error:
  43.                 msg = None
  44.                 s.close()
  45.                 s = None
  46.                 continue
  47.  
  48.             break
  49.         
  50.         return s
  51.  
  52.     
  53.     def _probe_queue(self, name, result):
  54.         s = self._open_socket()
  55.         if not s:
  56.             return False
  57.         
  58.         print name
  59.         
  60.         try:
  61.             s.send('\x00x02%s\n' % name)
  62.             data = s.recv(1024)
  63.             print repr(data)
  64.         except socket.error:
  65.             msg = None
  66.             print msg
  67.             
  68.             try:
  69.                 s.close()
  70.             except:
  71.                 pass
  72.  
  73.             return False
  74.  
  75.         if len(data) > 0 and data[0] == 0:
  76.             
  77.             try:
  78.                 s.send('\x00x01\n')
  79.                 s.close()
  80.             except:
  81.                 pass
  82.  
  83.             result.append(name)
  84.             return True
  85.         
  86.         
  87.         try:
  88.             s.close()
  89.         except:
  90.             pass
  91.  
  92.         return False
  93.  
  94.     
  95.     def probe(self):
  96.         result = []
  97.         for name in [
  98.             'PASSTHRU',
  99.             'ps',
  100.             'lp',
  101.             'PORT1',
  102.             '']:
  103.             self._probe_queue(name, result)
  104.             time.sleep(0.1)
  105.         
  106.         for nr in range(self.max_lpt_com):
  107.             self._probe_queue('LPT%d' % nr, result)
  108.             time.sleep(0.1)
  109.             self._probe_queue('LPT%d_PASSTHRU' % nr, result)
  110.             time.sleep(0.1)
  111.             self._probe_queue('COM%d' % nr, result)
  112.             time.sleep(0.1)
  113.             self._probe_queue('COM%d_PASSTHRU' % nr, result)
  114.             time.sleep(0.1)
  115.         
  116.         nr = 1
  117.         while nr < 50:
  118.             found = self._probe_queue('pr%d' % nr, result)
  119.             time.sleep(0.1)
  120.             if not found:
  121.                 break
  122.             
  123.             nr += 1
  124.         return result
  125.  
  126.  
  127.  
  128. class SocketServer:
  129.     
  130.     def __init__(self, hostname):
  131.         self.hostname = hostname
  132.  
  133.  
  134.  
  135. class IppServer:
  136.     
  137.     def __init__(self, hostname):
  138.         self.hostname = hostname
  139.  
  140.  
  141.